package com.zhuang.thread.ticket;

public class Ticket implements Runnable {

	int tickets = 100;

	Object obj = new Object();

	@Override
	public void run() {
		while(true) {
			synchronized (obj) {
				if (tickets > 0) {
					try {
						Thread.sleep(50);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					String name = Thread.currentThread().getName();
					System.out.println(name + "正在卖" + tickets--);
				}
			}
		}
	}

}
